// ==UserScript== // @name TikTok 测试 // @namespace http://tampermonkey.net/ // @version 5.31 // @description 获取 TikTok 数据并显示精简用户界面! // @author // @match *://*/* // @grant GM_registerMenuCommand // @grant GM_setValue // @grant GM_getValue // @grant GM_getResourceText // @grant GM_addStyle // @grant GM_xmlhttpRequest // @connect tiktok.com // @icon https://iili.io/dy5xjOg.jpg // @require https://code.jquery.com/jquery-3.6.0.min.js // @require https://cdnjs.cloudflare.com/ajax/libs/toastify-js/1.12.0/toastify.min.js // @resource TOASTIFY_CSS https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css // ==/UserScript== (function() { 'use strict'; console.log('Script loaded successfully'); // 加载 Toastify.js 的 CSS GM_addStyle(GM_getResourceText('TOASTIFY_CSS')); // 默认设置:页面加载时是否自动显示数据面板 let autoShowDataPanel = GM_getValue('autoShowDataPanel', false); console.log('Initial autoShowDataPanel:', autoShowDataPanel); // 注册菜单命令,切换是否自动显示数据面板 GM_registerMenuCommand('切换自动弹出数据面板', () => { autoShowDataPanel = !autoShowDataPanel; GM_setValue('autoShowDataPanel', autoShowDataPanel); alert(`自动弹出数据面板已${autoShowDataPanel ? '启用' : '禁用'}`); console.log('Toggled autoShowDataPanel to:', autoShowDataPanel); }); $(document).ready(function() { console.log('Document ready'); if (autoShowDataPanel) { initializeInterface(); } // 监听快捷键 Alt+N 来手动打开或关闭界面 $(document).on('keydown', function(e) { if (e.altKey && e.key === 'g') { console.log('Alt+G pressed'); toggleInterface(); } }); }); function initializeInterface() { console.log('Initializing interface'); if ($('#tiktok-data-ui').length) { console.log('Interface already initialized'); return; } const container = $( `

TikTok 数据面板

暂无数据,请手动刷新
` ); $('body').append(container); console.log('Appended interface container'); $('#tiktok-data-ui').animate({ right: '20px' }, 400); // 使界面可拖动 dragElement(document.getElementById('tiktok-data-ui'), document.getElementById('drag-handle')); $('#tiktok-url-input').on('keydown', function(e) { if (e.key === 'Enter') { let url = $(this).val().trim(); console.log('Entered URL:', url); if (url) { if (!url.startsWith('https://www.tiktok.com/')) { if (!url.startsWith('@')) { url = '@' + url; } url = `https://www.tiktok.com/${url}`; console.log('Formatted URL:', url); } fetchDataFromUrl(url); } else { showNotification('请输入有效的 TikTok 视频或用户链接'); } } }); } function toggleInterface() { console.log('Toggling interface'); const container = $('#tiktok-data-ui'); if (container.length) { container.remove(); console.log('Removed interface'); } else { initializeInterface(); } } function fetchDataFromUrl(url) { console.log('Fetching data from URL:', url); $('#data-output').text('正在获取数据...'); GM_xmlhttpRequest({ method: 'GET', url: url, headers: { 'User-Agent': navigator.userAgent, 'Accept': 'text/html' }, onload: function(response) { console.log('Data fetched, status:', response.status); if (response.status === 200) { const responseText = response.responseText; const scriptMatch = responseText.match(/